package com.yvdelx.cyclowomen.activity.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.yvdelx.R;

/**
 * Adapter for the head calendar
 */
public class HeaderCalendarCellAdapter extends BaseAdapter {

    private final String[] daysItem;

    private final Activity activity;

    public HeaderCalendarCellAdapter(Activity activity) {
        this.activity = activity;
        this.daysItem = this.activity.getResources().getStringArray(R.array.week_day_array);
    }

    @Override
    public int getCount() {
        return this.daysItem.length;
    }

    @Override
    public String getItem(int i) {
        return this.daysItem[i];
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View row, ViewGroup parent) { // Draw the head of the calendar
        if(row == null){
            LayoutInflater inflater=(LayoutInflater) this.activity
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            row = inflater.inflate(R.layout.screen_gridcell,parent,false);
        }

        if(row == null)
            return null;

        TextView dayTextView = (Button) row.findViewById(R.id.calendar_day_gridcell);

        dayTextView.setText(this.getItem(i));


        Resources resources = parent.getResources();

        if(resources != null) {
            dayTextView.setBackgroundColor(this.activity
                    .getResources().getColor(R.color.black_overlay));
            dayTextView.setTextColor(Color.WHITE);
        }

        return row;
    }
}
